
<!--------------------------------------------黄笠煌------------------------------------------------------------------>
<template>
    <!--Form 组件提供了表单验证的功能，只需要通过 rules 属性传入约定的验证规则，并将 Form-Item 的 prop 属性设置为需校验的字段名即可-->
    <!--:model用来绑定对象ruleForm，v-model绑定表单元素和对象属性，rules用来绑定校验规则,其中prop绑定表单元素和对应校验规则-->
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <!--ref相当于该form表单的名字，即用于提交事件的Formname-->
        <el-form-item label="条件id（不可修改）" >
            <el-input v-model="ruleForm.id" readonly></el-input><!--只读不可改-->
        </el-form-item>
        <el-form-item label="配送中心（不可修改）" prop="distributecentre">
            <el-input v-model="ruleForm.distributecentre" readonly></el-input><!--只读不可改-->
        </el-form-item>
        <el-form-item label="库房（不可修改）" prop="storage">
            <el-input v-model="ruleForm.storage" readonly></el-input><!--只读不可改-->
        </el-form-item>
        <el-form-item label="重量" prop="weight">
            <el-input v-model.number="ruleForm.weight" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
        </el-form-item>
        <el-form-item label="体积" prop="volume">
            <el-input v-model.number="ruleForm.volume" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
        </el-form-item>
        <el-form-item label="数量" prop="number">
            <el-input v-model.number="ruleForm.number" ></el-input><!--当验证的下类型为数字类型时需采用v-model.number绑定-->
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
           <!-- <el-button @click="resetForm('ruleForm')">重置</el-button>-->
           
        </el-form-item>

    </el-form>

</template>
<script>
    export default {
        data() {
            return {
                /*定义表单返回对象ruleForm*/
                ruleForm: {
                    id:'',
                    distributecentre: '',
                    storage: '',
                    weight: '',
                    volume: '',
                    number:'',

                },
                /*校验规则*/
                rules: {
                    distributecentre: [
                        { required: true, message: '请输入配送中心', trigger: 'blur' },

                    ],
                    storage: [
                        { required: true, message: '请输入库房', trigger: 'blur' }
                    ],
                    weight: [
                        { required: true, message: '请输入重量', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],
                    volume: [
                        { required: true, message: '请输入体积', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],
                    number: [
                        { required: true, message: '请输入数量', trigger: 'blur' },
                        {type:'number',message:'请输入数字',trigger:'blur'}
                    ],

                }
            };
        },
        methods: {
            test(){
                console.log(this.ruleForm)
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {

                        /*在此验证成功，将数据给后台*/
                        axios.put('http://localhost:8181/ruleUpById',this.ruleForm).then(function (resp) {
                            alert('submit!');

                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        created() {
            //由id查后端数据返回显示到表单中
           /* alert(this.$route.query.id)//测试成功！可以收到Displayrule页面传过来的id参数*/
            const _this=this
            axios.get('http://localhost:8181/ruleSelectById/'+this.$route.query.id).then(function(resp){
                _this.ruleForm=resp.data

            })

        }
    }
</script>